home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / krootpixmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  5.9 KB  |  217 lines

  1. /* vi: ts=8 sts=4 sw=4
  2.  *
  3.  * $Id: krootpixmap.h 345292 2004-09-09 20:07:27Z staniek $
  4.  * This file is part of the KDE project, module kdesktop.
  5.  * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
  6.  *
  7.  * You can Freely distribute this program under the GNU Library General
  8.  * Public License. See the file "COPYING.LIB" for the exact licensing terms.
  9.  */
  10.  
  11. #ifndef __KRootPixmap_h_Included__
  12. #define __KRootPixmap_h_Included__
  13.  
  14. #include <qobject.h>
  15. #include <qcolor.h>
  16. #include <kdelibs_export.h>
  17.  
  18. #ifndef Q_WS_QWS //FIXME
  19.  
  20. class QRect;
  21. class QWidget;
  22. class QTimer;
  23. class KSharedPixmap;
  24. class KRootPixmapData;
  25.  
  26. /**
  27.  * Creates pseudo-transparent widgets.
  28.  *
  29.  * A pseudo-transparent widget is a widget with its background pixmap set to
  30.  * that part of the desktop background that it is currently obscuring. This
  31.  * gives a transparency effect.
  32.  *
  33.  * To create a transparent widget, construct a KRootPixmap and pass it a
  34.  * pointer to your widget. That's it! Moving, resizing and background changes
  35.  * are handled automatically.
  36.  *
  37.  * Instead of using the default behavior, you can ask KRootPixmap
  38.  * to emit a backgroundUpdated(const QPixmap &) signal whenever
  39.  * the background needs updating by using setCustomPainting(bool).
  40.  * Alternatively by reimplementing updateBackground(KSharedPixmap*)
  41.  * you can take complete control of the behavior.
  42.  *
  43.  * @author Geert Jansen <jansen@kde.org>
  44.  * @version $Id: krootpixmap.h 345292 2004-09-09 20:07:27Z staniek $
  45.  */
  46. class KDEUI_EXPORT KRootPixmap: public QObject
  47. {
  48.     Q_OBJECT
  49.  
  50. public:
  51.     /**
  52.      * Constructs a KRootPixmap. The KRootPixmap will be created as a child
  53.      * of the target widget so it will be deleted automatically when the
  54.      * widget is destroyed.
  55.      *
  56.      * @param target A pointer to the widget that you want to make pseudo
  57.      * transparent.
  58.      * @param name The internal name of the pixmap
  59.      */
  60.     KRootPixmap( QWidget *target, const char *name=0 );
  61.  
  62.     /**
  63.      * Constructs a KRootPixmap where the parent QObject and target QWidget are
  64.      * different.
  65.      */
  66.     KRootPixmap( QWidget *target, QObject *parent, const char *name=0 );
  67.  
  68.     /**
  69.      * Destructs the object.
  70.      */
  71.     virtual ~KRootPixmap();
  72.  
  73.     /**
  74.      * Checks if pseudo-transparency is available.
  75.      * @return @p true if transparency is available, @p false otherwise.
  76.      */
  77.     bool isAvailable() const;
  78.  
  79.     /**
  80.      * Returns true if the KRootPixmap is active.
  81.      */
  82.     bool isActive() const { return m_bActive; }
  83.  
  84.     /**
  85.      * Returns the number of the current desktop.
  86.      */
  87.     int currentDesktop() const;
  88.  
  89.     /**
  90.      * Returns true if custom painting is enabled, false otherwise.
  91.      * @see setCustomPainting(bool)
  92.      */
  93.     bool customPainting() const { return m_bCustomPaint; }
  94.  
  95. #ifndef KDE_NO_COMPAT
  96.     /**
  97.      * Deprecated, use isAvailable() instead.
  98.      * @deprecated
  99.      */
  100.     KDE_DEPRECATED bool checkAvailable(bool) { return isAvailable(); }
  101. #endif
  102.  
  103.     /** @since 3.2
  104.      * @return the fade color.
  105.      */
  106.     const QColor &color() const { return m_FadeColor; }
  107.  
  108.     /** @since 3.2
  109.      * @return the color opacity.
  110.      */
  111.     double opacity() const { return m_Fade; }
  112.  
  113. public slots:
  114.     /**
  115.      * Starts background handling.
  116.      */
  117.     virtual void start();
  118.  
  119.     /**
  120.      * Stops background handling.
  121.      */
  122.     virtual void stop();
  123.  
  124.     /**
  125.      * Sets the fade effect.
  126.      *
  127.      * This effect will fade the background to the
  128.      * specified color.
  129.      * @param opacity A value between 0 and 1, indicating the opacity
  130.      * of the color. A value of 0 will not change the image, a value of 1
  131.      * will use the fade color unchanged.
  132.      * @param color The color to fade to.
  133.      */
  134.     void setFadeEffect(double opacity, const QColor &color);
  135.  
  136.     /**
  137.      * Repaints the widget background. Normally, you shouldn't need this
  138.      * as it is handled automatically.
  139.      *
  140.      * @param force Force a repaint, even if the contents did not change.
  141.      */
  142.     void repaint( bool force );
  143.  
  144.     /**
  145.      * Repaints the widget background. Normally, you shouldn't need this
  146.      * as it is handled automatically. This is equivalent to calling
  147.      * repaint( false ).
  148.      */
  149.     void repaint();
  150.  
  151.     /**
  152.      * Enables custom handling of the background painting. If custom
  153.      * painting is enabled then KRootPixmap will emit a
  154.      * backgroundUpdated() signal when the background for the
  155.      * target widget changes, instead of applying the new background.
  156.      */
  157.     void setCustomPainting( bool enable ) { m_bCustomPaint = enable; }
  158.  
  159.     /**
  160.      * Asks KDesktop to export the desktop background as a KSharedPixmap.
  161.      * This method uses DCOP to call KBackgroundIface/setExport(int).
  162.      */
  163.     void enableExports();
  164.  
  165.     /**
  166.      * Returns the name of the shared pixmap (only needed for low level access)
  167.      */
  168.     static QString pixmapName(int desk);
  169. signals:
  170.     /**
  171.      * Emitted when the background needs updating and custom painting
  172.      * (see setCustomPainting(bool) ) is enabled.
  173.      *
  174.      * @param pm A pixmap containing the new background.
  175.      */
  176.     void backgroundUpdated( const QPixmap &pm );
  177.  
  178. protected:
  179.     /**
  180.      * Reimplemented to filter the events from the target widget and
  181.      * track its movements.
  182.      */
  183.     virtual bool eventFilter(QObject *, QEvent *);
  184.  
  185.     /**
  186.      * Called when the pixmap has been updated. The default implementation
  187.      * applies the fade effect, then sets the target's background, or emits
  188.      * backgroundUpdated(const QPixmap &) depending on the painting mode.
  189.      */
  190.     virtual void updateBackground( KSharedPixmap * );
  191.  
  192. private slots:
  193.     void slotBackgroundChanged(int);
  194.     void slotDone(bool);
  195.     void desktopChanged(int desktop);
  196.     void desktopChanged( WId window, unsigned int properties );
  197.  
  198. private:
  199.     bool m_bActive, m_bInit, m_bCustomPaint;
  200.     int m_Desk;
  201.  
  202.     double m_Fade;
  203.     QColor m_FadeColor;
  204.  
  205.     QRect m_Rect;
  206.     QWidget *m_pWidget;
  207.     QTimer *m_pTimer;
  208.     KSharedPixmap *m_pPixmap;
  209.     KRootPixmapData *d;
  210.  
  211.     void init();
  212. };
  213.  
  214. #endif // ! Q_WS_QWS
  215. #endif // __KRootPixmap_h_Included__
  216.  
  217.